#ifndef DISPLAY_CLASS_H
#define DISPLAY_CLASS_H

#include <string>
#include <vector>
#include <allegro5/allegro.h>
#include <allegro5/allegro_color.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5\allegro_native_dialog.h>

#include "colour.h"
#include "GlobalVariables.h"
#include "Point.h"
#include "Utilities.h"

#include "Movables.h"
#include "Monster.h"
#include "Digdug.h"
#include "Projectile.h"


using std::string;

//! \brief Interface class responsible for initializing Allegro, creating an Allegro display and drawing to the display.

class Display
{
public:
	Display();
	~Display();
	
	// update the display
	void update();			//!<Draws elemets & updates display
	void clearBuffer();		//!Resets the back buffer
	void startTimer();		//!Starts the event que timer

	//Allow access to the event queue
	ALLEGRO_EVENT_QUEUE* event_queue();	//!Returns the event stack

	//Bitmap Draw Routines

	/*! \brief A useful function which draws each map element in a different colour according to its object type.
	 
		It takes in the map information in the form of a 2D vector of object types. 
	*/
	void drawAsGrid(vector <vector <Movable_type>> map) const; 
	
	/*! \brief Draws the sand to the screen. 
		
		The function makes bitmaps for the sand elements, colouring them according to how far down on the screen they appear, 
		i.e. according to the values of their y coordinates.
		This gives the playing screen a feel similar to that in the original Dig Dug game and indicates how the points scored for 
		digging through sand change as Dig Dug digs lower down in the game grid.

		The map, passed by value for efficiency, is used to locate the sand elements in the playing screen.
		No data members of the class or the map should be changed by this function. This is enforced by making it a constant function.
	*/
	void drawMap(Map& map) const;


	void drawBoxesToScreen();

	/*! \brief This loops through all the monsters that are passed to it and draws their bitmaps on the screen in the correct location.
	
		If the monsters are in their disembodied or 'ghost' froms, they are drawn in a different colour to normal.
		If a monster is being inflated by Dig Dug's projectile, the size of the monster's bitmap is drawn to the scale indicated by
		its degree of inflation.
	*/
	void drawMonsters( vector <Monster> &monsters) const;

	//! \brief This draws Dig Dug according to his bitmap in the correct location on the screen
	void drawDigdug( Digdug &digdug) const;
	
	/*! This draws Dig Dug's projectile in its location on the screen according to its bitmap

		As the projectile moves further away from Dig Dug, its bitmap is strethced in the direction it is shot
		so that it is seen to be extending from Dig Dug.
	*/
	void drawProjectile(Projectile &projectile, Digdug &digdug) const;
	
	/*! \brief This is used to write to the screen in the main menu at the end of each game,
		giving the option to exit or play again.

		The text printed by this function could easily be modified to present more options on the main menu
		in future development of the game
	*/
	void drawMessage(string message, string colour);

	/*! \brief This draws the score box on the right hand side of the playing screen

	It takes in values such as the score, high score, level and number of lives the player has left in the game
	and draws them to the screen.
	*/
	void drawScoreBox(int score, int lives, int high_score, int level);

	//! \brief This provides a useful means of communication with the user. 
	//!If options are introduced to the game, this function can be used to offer the user a choice and ellicit feedback. 
	int showNativeDialogMessageQuestion(char const *title, char const *text);
	
	//! \brief Can be used to provide a message to the user.
	void showNativeDialogMessageOK(char const *title, char const *heading, char const *text);

private:
	
	void initialiseAllegroComponents() const;
	void allocateAllegroResources();

	int _display_width;
	int _display_height;
	void drawScaledBitmap(Point location, int radius,int scale,  ALLEGRO_BITMAP *bitmap) const;

	
	// pointers to Allegro resources
	ALLEGRO_DISPLAY* _display;
	ALLEGRO_EVENT_QUEUE* _event_queue;
	ALLEGRO_TIMER *_timer;
	ALLEGRO_FONT* _font32;
	ALLEGRO_FONT* _font24;
	ALLEGRO_FONT* _font60;

	ALLEGRO_BITMAP* _game_box;
	ALLEGRO_BITMAP* _score_box;

};


#endif